#require 'minitest/autorun'
require 'test/unit'
require 'digest/ed2k'

class Zeroes < Test::Unit::TestCase
    def test_zero_length_file
        assert_equal '31d6cfe0d16ae931b73c59d7e0c089c0',
            Digest::ED2k.hexdigest('')
    end

    def add_by_random_chunks (str, ed2k = Digest::ED2k.new)
        loops = 2000 # don't let bad random numbers freeze the test
        while str.length > 1 && loops > 0
            r = rand(str.length)
            ed2k << str[0...r]
            str = str[r...str.length]
            loops -= 1
        end
        ed2k << str
    end

    def test_single_chunk_zero_file
        assert_equal 'fc21d9af828f92a8df64beac3357425d',
            add_by_random_chunks("\0" * Digest::ED2k::CHUNK_SIZE).hexdigest
    end

    def test_two_chunk_zero_file
        assert_equal '114b21c63a74b6ca922291a11177dd5c',
            add_by_random_chunks("\0" * (2 * Digest::ED2k::CHUNK_SIZE)).hexdigest
    end

    def test_two_and_half_chunk_zero_file
        assert_equal 'a4b0b40d5b13bb045b0ce2a8fad8b393',
             add_by_random_chunks("\0" * (5 * Digest::ED2k::CHUNK_SIZE / 2)).hexdigest
    end

    def test_three_and_half_chunk_by_object_random
        assert_equal '57d514e8e464257aca18e50e47194e42',
            add_by_random_chunks("\0" * (7 * Digest::ED2k::CHUNK_SIZE / 2)).hexdigest
    end
end
